from datetime import datetime

from celery.utils.time import timezone
from django.db import models

from user.models import User




# 基类
class Base(models.Model):
    # 创建时间
    create_time = models.DateTimeField(auto_now_add=True, null=True)
    update_time = models.DateTimeField(auto_now=True, null=True)
    class Meta:
        abstract = True

# 类别表   (免费, 限免, 会员)
class Category(Base):
    name = models.CharField("类别标签", max_length=256)


# 标签表   (Python, C/C++, Java, Linux .....)
class Label(Base):
    title = models.CharField('标签名', max_length=64)


# 课程表
class Course(Base):
    course_status = (
        (1, '已上线'),
        (2, '即将上线'),
        (3, '下架'),
    )
    title = models.CharField('课程标题', max_length=128, unique=True)
    desc = models.TextField('课程描述')
    img = models.ImageField('课程图片', null=True, upload_to='media')
    type = models.ForeignKey(Category, on_delete=models.SET_NULL, verbose_name='关联课程类别', null=True)
    tag = models.ForeignKey(Label, on_delete=models.SET_NULL, verbose_name='关联标签外键', null=True)
    status = models.IntegerField(choices=course_status)
    attenttion_num = models.IntegerField('关注人数')

# 章表
class Section(Base):
    title = models.CharField('章节名称', max_length=64)
    title_num = models.CharField('章节号', max_length=8)
    course_id = models.ForeignKey(Course, on_delete=models.SET_NULL, verbose_name='所属课程', null=True)

# 节表
class Jie(Base):
    title = models.CharField('章节名称', max_length=64)
    title_num = models.CharField('章节号', max_length=8)
    section_id = models.ForeignKey(Section, on_delete=models.SET_NULL, verbose_name='章节id', null=True)


# 关注表
class Attention(Base):
    attention_status = (
        (0, '关注'),
        (1, '取消关注')
    )
    user_id = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='关注用户的id')
    course_id = models.ForeignKey(Course, on_delete=models.SET_NULL, verbose_name='关注课程的id', null=True)
    status = models.IntegerField('关注的状态', choices=attention_status)

# 我的课程
class MyCourse(Base):
    course_status = (
        (0, '加入课程'),
        (1, '删除课程')
    )
    user_id = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='关注用户的id')
    course_id = models.ForeignKey(Course, on_delete=models.SET_NULL, verbose_name='关注课程的id', null=True)
    status = models.IntegerField('关注的状态', choices=course_status)